import { reactive } from '../reactive'
import { effectWatch } from '../reactive/effect'
import Watcher from '../reactive/watcher'
import { createMount } from '../runtime-core'
import { nextTick } from '../runtime-core/nextTick'

export default function Vue(options) {
  this.$options = options
  this.initLife()
  this.initState()
}

function initState() {
  const { data } = this.$options
  reactive(data)
  this.$data = data
  // 绑定到this上
  Object.keys(data).forEach(key => {
    Object.defineProperty(this, key, {
      get() {
        return data[key]
      },
      set(val) {
        data[key] = val
      },
      configurable: false,
      enumerable: true
    })
  })
}

function createWatch(expressFn, fn) {
  effectWatch(expressFn, fn)
}

function initLife() {
  this.$components = Object.create(null)
}

// Vue.prototype.initMixin = initMixin
Vue.prototype.initState = initState
Vue.prototype.$mount = createMount
Vue.prototype.initLife = initLife
Vue.prototype.$nextTick = nextTick
Vue.prototype.$watch = createWatch
// Vue.prototype.$emit = createEmit
// Vue.prototype.$set = createSet

// Vue.use = createUse
// Vue.components = createComponents
// Vue.directive = createDirective
// Vue.mixins = createMixins
// Vue.extends = createExtends

// window.Vue = Vue
